package com.dodoke.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dodoke.dto.RetailStoreDTO;
import com.dodoke.entity.RetailStore;
import com.dodoke.mapper.RetailStoreMapper;
import com.dodoke.service.IRetailStoreService;
import com.dodoke.vo.RetailStoreDetailVO;
import com.dodoke.vo.RetailStoreListVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 门店管理业务实现
 */
@Service
public class RetailStoreServiceImpl extends ServiceImpl<RetailStoreMapper, RetailStore> implements IRetailStoreService {
    @Resource
    private RetailStoreMapper retailStoreMapper;

    /**
     * 门店管理分页列表
     *
     * @param currentPage    当前页码
     * @param pageSize       每页显示条数
     * @param retailStoreDTO 模糊查询条件
     * @return
     */
    @Override
    public Page<RetailStoreListVO> getListByPage(Integer currentPage, Integer pageSize, RetailStoreDTO retailStoreDTO) {
        Page<RetailStoreListVO> page = new Page<>(currentPage, pageSize);
        page = retailStoreMapper.selectByList(page, retailStoreDTO);
        return page;
    }

    /**
     * 新增门店/网点
     *
     * @param retailStore
     * @return
     */
    @Override
    public int saveRetailStore(RetailStore retailStore) {
        retailStore.setDelFlag("0");
        return retailStoreMapper.insertRetailStore(retailStore);
    }

    /**
     * 门店/网点修改
     *
     * @param retailStore
     * @return
     */
    @Override
    public int editRetailStore(RetailStore retailStore) {
        return retailStoreMapper.updateRetailStore(retailStore);
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return
     */
    @Override
    public RetailStoreDetailVO getById(Long id) {
        RetailStore retailStore = retailStoreMapper.selectById(id);
        RetailStoreDetailVO retailStoreDetailVO = JSON.parseObject(JSON.toJSONString(retailStore), RetailStoreDetailVO.class);
        return retailStoreDetailVO;
    }
}
